import os
import sys
INPUTFILENAME = max(sys.argv[1:],"A-small-practice.in")
OUTFILENAME = max(sys.argv[2:],"A-small-practice.out")

#def countoperations(grade_str):
    #op_count = 0
    #stack = ""
    #for i,ltr  in enumerate(grade_str):
        #op_count += 1
        #if i > 0 and ltr <> grade_str[i-1]:
            #op_count += 1
    #return op_count

class Stamp_stack:
    def push(self,push_letter):
        self.stack += push_letter
        self.count_ops += 1
    def pop(self):
        self.stack = self.stack[:-1]
        self.count_ops += 1
    def ppt(self): self.count_ops +=1
    def __init__(self, grade_str):
        self.count_ops = 0
        self.stack = ""
        for i,ltr  in enumerate(grade_str):
            if not self.stack: self.push(ltr)
            if i > 0 and ltr <> grade_str[i-1]:
                if ltr not in self.stack:
                    self.push(ltr)
                else:
                    for j in range(len(self.stack) - self.stack.index(ltr) - 1):
                        self.pop()
            self.ppt()
        print self.stack
        for i in range(len(self.stack)):
            self.pop()

out_inf = []
with open(INPUTFILENAME) as in_file:
    in_file.readline()
    file_pos = 1
    for s in in_file.readlines():
        stamp = Stamp_stack(s.strip())
        out_inf.append("Case #" + str(file_pos) + ": " + str(stamp.count_ops) + "\n")
        file_pos += 1
     

with open(OUTFILENAME,"w") as out_file:
    out_file.writelines(out_inf)
    
pass